package 二叉树.练习;
//二叉树的构建及遍历
import java.util.Scanner;

class TreeNode{
    char val;
    TreeNode left;
    TreeNode right;
    TreeNode(char val){
        this.val = val;
    }
}


public class Text_6 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str = in.nextLine();
            TreeNode root = creatTree(str);

            inOrder(root);
        }

    }

    public static int i = 0;
    public static TreeNode creatTree(String str){
        char s = str.charAt(i);
        TreeNode root = null;
        if(s!='#'){
            root = new TreeNode(s);
            i++;
            root.left = creatTree(str);
            root.right = creatTree(str);
        }else{
            i++;
        }
        return root;
    }

    public static void inOrder(TreeNode root){
        if(root ==null){
            return ;
        }
        inOrder(root.left);
        System.out.print(root.val+" ");
        inOrder(root.right);
    }
}